package com.leruan.aasimp.dao.impl;

import java.util.List;

import org.hibernate.Session;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.leruan.aasimp.dao.BoardDao;
import com.leruan.aasimp.entity.Board;

public class BoardDaoImpl extends HibernateDaoSupport implements BoardDao {

    public List<Board> findBoard() {
        Session session = this.getSession();
        String hql = "from Board";
        List<Board> boards = getHibernateTemplate().find(hql);
        return boards;
    }

    public void updateBoardHits(Board board) {
        getHibernateTemplate().update(board);
    }

    public Board findBoardById(String boardId) {
        Session session = this.getSession();
        String hql = "from Board where boardId=?";
        return (Board) session.createQuery(hql).setString(0, boardId).uniqueResult();
    }

    public void insertBoard(Board board) {
        Session session = this.getSession();
        session.save(board);
    }

    public void updateBoardUser(String userId, Object object) {
        Session session = this.getSession();
        String hql = "update Board set boardUserId='null' where boardUserId=?";
        session.createQuery(hql).setString(0, userId).executeUpdate();
    }

}
